package com.itheima.udp2;

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.InetAddress;
import java.net.MulticastSocket;

public class ReceiveClient {

    public static void main(String[] args) throws IOException {
        //创建接收端对象
        MulticastSocket ms = new MulticastSocket(10086);
        // 加入群聊
        ms.joinGroup(InetAddress.getByName("224.0.1.0"));

        //创建容器
        byte[] bytes = new byte[64 * 1024];
        DatagramPacket dp = new DatagramPacket(bytes, bytes.length);
        while (true) {
            //接收数据
            ms.receive(dp);
            int length = dp.getLength();

            //展示数据
            String s = new String(bytes, 0, length);
            System.out.println(s);
        }
        //释放资源



    }
}
